const path = require('path')

const config = {
  projectName: 'taro3_react',
  date: '2020-8-10',
  designWidth: 750,
  deviceRatio: {
    640: 2.34 / 2,
    750: 1,
    828: 1.81 / 2,
  },
  sourceRoot: 'src',
  outputRoot: 'dist',
  plugins: [],
  defineConstants: {},
  alias: {
    '@/vant': path.resolve(__dirname, '../src/components/vant-weapp/dist'),
    '@/components': path.resolve(__dirname, '..', 'src/components'),
    '@/utils': path.resolve(__dirname, '..', 'src/utils'),
    '@/assets': path.resolve(__dirname, '..', 'src/assets'),
    '@/actions': path.resolve(__dirname, '..', 'src/actions'),
    '@/services': path.resolve(__dirname, '..', 'src/services'),
    '@/reducers': path.resolve(__dirname, '..', 'src/reducers'),
  },
  copy: {
    patterns: [
      {
        from: 'src/components/vant-weapp/dist/wxs',
        to: 'dist/components/vant-weapp/dist/wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/common/style',
        to: 'dist/components/vant-weapp/dist/common/style',
      },
      {
        from: 'src/components/vant-weapp/dist/common/index.wxss',
        to: 'dist/components/vant-weapp/dist/common/index.wxss',
      },
      {
        from: 'src/components/vant-weapp/dist/calendar/index.wxs',
        to: 'dist/components/vant-weapp/dist/calendar/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/calendar/utils.wxs',
        to: 'dist/components/vant-weapp/dist/calendar/utils.wxs',
      },
      {
        from:
          'src/components/vant-weapp/dist/calendar/components/month/index.wxs',
        to:
          'dist/components/vant-weapp/dist/calendar/components/month/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/area/index.wxs',
        to: 'dist/components/vant-weapp/dist/area/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/button/index.wxs',
        to: 'dist/components/vant-weapp/dist/button/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/calendar/index.wxs',
        to: 'dist/components/vant-weapp/dist/calendar/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/cell/index.wxs',
        to: 'dist/components/vant-weapp/dist/cell/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/checkbox/index.wxs',
        to: 'dist/components/vant-weapp/dist/checkbox/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/col/index.wxs',
        to: 'dist/components/vant-weapp/dist/col/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/config-provider/index.wxs',
        to: 'dist/components/vant-weapp/dist/config-provider/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/divider/index.wxs',
        to: 'dist/components/vant-weapp/dist/divider/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/dropdown-menu/index.wxs',
        to: 'dist/components/vant-weapp/dist/dropdown-menu/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/empty/index.wxs',
        to: 'dist/components/vant-weapp/dist/empty/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/field/index.wxs',
        to: 'dist/components/vant-weapp/dist/field/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/grid/index.wxs',
        to: 'dist/components/vant-weapp/dist/grid/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/grid-item/index.wxs',
        to: 'dist/components/vant-weapp/dist/grid-item/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/icon/index.wxs',
        to: 'dist/components/vant-weapp/dist/icon/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/image/index.wxs',
        to: 'dist/components/vant-weapp/dist/image/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/loading/index.wxs',
        to: 'dist/components/vant-weapp/dist/loading/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/nav-bar/index.wxs',
        to: 'dist/components/vant-weapp/dist/nav-bar/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/notice-bar/index.wxs',
        to: 'dist/components/vant-weapp/dist/notice-bar/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/notify/index.wxs',
        to: 'dist/components/vant-weapp/dist/notify/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/picker/index.wxs',
        to: 'dist/components/vant-weapp/dist/picker/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/picker-column/index.wxs',
        to: 'dist/components/vant-weapp/dist/picker-column/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/popup/index.wxs',
        to: 'dist/components/vant-weapp/dist/popup/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/progress/index.wxs',
        to: 'dist/components/vant-weapp/dist/progress/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/radio/index.wxs',
        to: 'dist/components/vant-weapp/dist/radio/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/row/index.wxs',
        to: 'dist/components/vant-weapp/dist/row/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/share-sheet/index.wxs',
        to: 'dist/components/vant-weapp/dist/share-sheet/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/share-sheet/options.wxs',
        to: 'dist/components/vant-weapp/dist/share-sheet/options.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/slider/index.wxs',
        to: 'dist/components/vant-weapp/dist/slider/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/stepper/index.wxs',
        to: 'dist/components/vant-weapp/dist/stepper/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/sticky/index.wxs',
        to: 'dist/components/vant-weapp/dist/sticky/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/switch/index.wxs',
        to: 'dist/components/vant-weapp/dist/switch/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/tabs/index.wxs',
        to: 'dist/components/vant-weapp/dist/tabs/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/tag/index.wxs',
        to: 'dist/components/vant-weapp/dist/tag/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/transition/index.wxs',
        to: 'dist/components/vant-weapp/dist/transition/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/tree-select/index.wxs',
        to: 'dist/components/vant-weapp/dist/tree-select/index.wxs',
      },
      {
        from: 'src/components/vant-weapp/dist/uploader/index.wxs',
        to: 'dist/components/vant-weapp/dist/uploader/index.wxs',
      },
    ],
    options: {},
  },
  framework: 'react',
  mini: {
    postcss: {
      pxtransform: {
        enable: true,
        config: {
          selectorBlackList: [/van-/],
        },
      },
      url: {
        enable: true,
        config: {
          limit: 1024, // 设定转换尺寸上限
        },
      },
      cssModules: {
        enable: true, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]',
        },
      },
    },
  },
  h5: {
    publicPath: '/',
    staticDirectory: 'static',
    router: {
      mode: 'hash',
      customRoutes: {
        '/pages/index/index': '/',
      },
    },
    postcss: {
      autoprefixer: {
        enable: true,
        config: {},
      },
      cssModules: {
        enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]',
        },
      },
    },
  },
}

module.exports = function(merge) {
  if (process.env.NODE_ENV === 'development') {
    return merge({}, config, require('./dev'))
  }
  return merge({}, config, require('./prod'))
}
